#!/bin/bash
# dws数据导入到mysql 
# 先删除掉mysql中年的数据,再进行导入
export SQOOP_HOME=/usr/bin/sqoop
if [ $# -eq 1 ]
then
datastr=`date -d '-1 day' +%Y-%m-%d`
else
datastr=$1
fi
yearstr=`date +%Y`
mysql -uroot -p123456 -hhadoop01 -P3306 -e "delete from nev.result.data_result where yearinfo='${yearstr}';" 
echo "delete from nev.result.data_result where yearinfo='${yearstr}'" 
${SQOOP_HOME} export \
--connect "jdbc:mysql://hadoop01:3306/nev_result?useUnicode=true&characterEncoding=utf-8" \
--username root \
--password '123456' \
--table data_result \
--hcatalog-database macmillanedu_dws \
--hcatalog-table visit_dws \
--hcatalog-partition-keys yearinfo \
--hcatalog-partition-values ${yearstr} \
-m 1





